<?php use_helper('Number') ?>
<?php use_helper('Javascript') ?>

<div class="category_title">
    <?php echo __('watchlist') ?>
</div>

<?php if( $arMyList ): ?>

<div class="cart_history">
    <?php echo link_to(
                    image_tag(
                        'cross.png'
                        , array(
                            'border' => '0'
                            , 'alt' => __('clear all')
                            , 'title' => __('clear all')
                            , 'style' => 'margin-bottom: -4px;'
                        )
                    )
                    , 'product/clearwatchlist'
                ) ?>
    <?php echo link_to(
                    __('clear all')
                    , 'product/clearwatchlist'
                ) ?>
</div>

<hr class="hr_search" />

<div class="products">

    <?php foreach( $arMyList as $product ): ?>
    <div class="product">

        <div class="watch">
            <?php echo link_to(
                            image_tag(
                                'cross.png'
                                , array(
                                    'border' => '0'
                                    , 'alt' => __('Remove from list')
                                    , 'title' => __('Remove from list')
                                )
                            )
                            , 'product/removefromlist/?id='.$product->getId()
                        ) ?>
        </div>
        <div class="product_title">
            <?php echo link_to($product->getName(), 'product/show/?id='.$product->getId()); ?>
        </div>

        <div class="product_image">
        <?php if( $product->hasPhoto($product->getId()) ): ?>
            <?php echo link_to(
                            image_tag(
                                Files::getDirPath('tiny').$product->getPhotoName($product->getId())
                                , array(
                                    'border' => '0'
                                    , 'alt' => $product->getName()
                                    , 'title' => $product->getName()
                                )
                            )
                            , 'product/show/?id='.$product->getId()
                        )
                    ?> 
        <?php else: ?>
            ---
        <?php endif; ?>
        </div>

        <div class="product_price">
            <?php if($product->hasTag(Product::PROMO_TAG)): ?>
                <span style="text-decoration: line-through;"><?php echo format_currency($product->getPriceByCurrencyCode($sf_user->getAttribute('currency', 'EUR')), $sf_user->getAttribute('currency', 'EUR')) ?></span>
                <?php echo format_currency($product->getPromoPriceByCurrencyCode($sf_user->getAttribute('currency', 'EUR'))
                                        , $sf_user->getAttribute('currency', 'EUR'))?>
            <?php else: ?>
            	<?php echo format_currency($product->getPriceByCurrencyCode($sf_user->getAttribute('currency', 'EUR')), $sf_user->getAttribute('currency', 'EUR')) ?>
            <?php endif; ?>
        </div>

            <?php if( get_user_id() ): ?>
        <div>
            <span id="ci_<?php echo $product->getId() ?>" style="display: none;">...</span><br />
            <input type="text" id="pr_<?php echo $product->getId() ?>" value="1" class="add_total" />
            <?php echo link_to(image_tag('cart_small.png'
                                        , array('border' => '0'
                                              , 'alt' => __('Add to basket')
                                              , 'title' => __('Add to basket')
                                              , 'style' => 'margin: 0 2px -4px 2px;'))
                              , '#'
                              , array( 'onclick' => 'addToCart('. $product->getId() .'); return false;'))?>
            <?php echo link_to(__('Add to basket')
                            , '#'
                            , array( 'onclick' => 'addToCart('. $product->getId() .'); return false;'))?>
        </div> 

            <?php else: ?>
                ---
            <?php endif; ?>
        <div>
            <?php echo $product->getCode() ?>
        </div>
        <div>
            <?php echo $product->getSummary() ?>
        </div>

    </div>

    <?php endforeach; ?>

</div>

<hr class="hr_search" />

<div class="cart_history">
    &nbsp;&nbsp;&nbsp;
    <?php echo link_to(
                    image_tag(
                        'cross.png'
                        , array(
                            'border' => '0'
                            , 'alt' => __('clear all')
                            , 'title' => __('clear all')
                            , 'style' => 'margin-bottom: -4px;'
                        )
                    )
                    , 'product/clearwatchlist'
                ) ?>
    <?php echo link_to(
                    __('clear all')
                    , 'product/clearwatchlist'
                ) ?>
</div>

<?php else: ?>
    <?php echo __('No items in your watch list') ?>
<?php endif; ?>
<script type="text/javascript">
function addToCart(id)
{
    jQuery.ajax({
        type: "post"
        , data: ({'id' : id, qnt : jQuery('#pr_'+id).val() })
        , dataType: "html"
        , url: "/st.php/lt/cart/add"
        , success: function(data) {
            jQuery('#divCartStatus').html(data);
            OnCartItemAdded(id);
          }
        , error: function() { OnCartItemFailed(id); }
    });
}
</script>